package edu.arizona.mindseye.swing;

import java.awt.BorderLayout;
import java.util.List;

import javax.swing.DefaultListModel;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;

import edu.arizona.mindseye.event.Event;
import edu.arizona.mindseye.event.EventListener;
import edu.arizona.mindseye.event.EventManager;
import edu.arizona.mindseye.event.enums.EventType;
import edu.arizona.mindseye.event.enums.Parameter;

public class DisplayBehaviorsDialog extends JDialog {

	private JList _list;
	private DefaultListModel _model;
	
	public DisplayBehaviorsDialog() { 
		super((JFrame) null, "Available Behaviors", false);
		
		addComponents();
		addListeners();
	}
	
	private void addComponents() { 
		_model = new DefaultListModel();
		_list = new JList(_model);
		
		setLayout(new BorderLayout());
		add(new JScrollPane(_list), BorderLayout.CENTER);
		setSize(200, 300);
	}
	
	private void addListeners() { 
		EventManager.inst().register(EventType.BEHAVIORS, new EventListener() {
			@Override
			public void onEvent(Event e) {
				_model.clear();
				
				List<String> behaviors = (List<String>) e.getValue(Parameter.behaviors);
				for (String s : behaviors)
					_model.addElement(s);
			} 
		});
	}
}
